package findTheLongestBalancedSubstring;

public class Solution {
    public int findTheLongestBalancedSubstring(String s) {
        // 遍历
        int ans = 0;
        int i = 0;
        while (i<s.length()) {
            int zero = 0; // 0的数量
            while (i<s.length()&&s.charAt(i) == '0') {
                i++;
                zero++;
            }
            int one = 0; // 1的数量
            while (i<s.length()&&s.charAt(i) == '1') {
                i++;
                one++;
            }
            ans = Math.max(Math.min(zero,one),ans);
        }
        return ans*2;
    }
}
